<template>
  <div class="left-chart-1">
    <div class="lc1-header">温湿度实时变化趋势</div>
    <v-chart style="width:100%;height:100%;" :autoresize="true" :options="option"/>
    <dv-decoration-2 style="height:10px;" />
  </div>
</template>

<script>
export default {
  name: 'LeftChart1',
  props: {
    servicePersonsData: {
      type: Array
    },
    enterPersonsData: {
      type: Array
    },
    serviceEnterRate: {
      type: Array
    },
    axisDataList: {
      type: Array
    }
  },
  data () {
    return {
      option: {
        color: ['#19be6b', '#ff9900'],
        title: {
          text: ''
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['温度', '湿度']
        },
        // toolbox: {
        //   show: true,
        //   feature: {
        //     magicType: { type: ['line', 'bar'] },
        //     restore: {},
        //     saveAsImage: {}
        //   }
        // },
        grid: {
          top: '32%',
          left: '4%',
          right: '6%'
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: this.axisDataList
        },
        yAxis: [{
          type: 'value',
          name: 'C',
          axisLabel: {
            formatter: '{value}'
          }
        },
        {
          type: 'value',
          show: true,
          name: '%',
          axisLabel: {
            formatter: '{value}'
          },
          axisTick: {
            show: true
          },
          axisLine: {
            lineStyle: {
              width: 1
            }
          }
        }],
        series: [
          {
            name: '温度',
            type: 'line',
            data: this.enterPersonsData,
            label: {
              show: false,
              fontSize: 14
            },
            markPoint: {
              data: [
                { type: 'max', name: '最大值' },
                { type: 'min', name: '最小值' }
              ]
            },
            markLine: {
              label: {
                fontSize: 14,
                formatter: (params) => {
                  return Math.round(params.value)
                }
              },
              data: [{ type: 'average', name: '平均值' }]
            },
            areaStyle: {}
          },
          {
            name: '湿度',
            type: 'line',
            label: {
              show: false
            },
            yAxisIndex: 1, // 多个 y 轴时使用
            data: this.servicePersonsData,
            markPoint: {
              data: [
                { type: 'max', name: '最大值' },
                { type: 'min', name: '最小值' }
              ]
            },
            markLine: {
              label: {
                fontSize: 14,
                formatter: (params) => {
                  return Math.round(params.value)
                }
              },
              data: [{ type: 'average', name: '平均值' }]
            },
            areaStyle: {}
          }
          // {
          //   name: '进店服务率',
          //   type: 'line',
          //   label: {
          //     show: false
          //   },
          //   markPoint: {
          //     data: [
          //       { type: 'max', name: '最大值' },
          //       { type: 'min', name: '最小值' }
          //     ]
          //   },
          //   yAxisIndex: 1, // 多个 y 轴时使用
          //   data: this.serviceEnterRate
          // }
        ]
      }
    }
  },
  watch: {
    enterPersonsData: {
      deep: true,
      handler (value) {
        // console.log('进店人次新的值：', value)
        this.option.series[0].data = value
      }
    },
    servicePersonsData: {
      deep: true,
      handler (value) {
        // console.log('服务人次新的值：', value)
        this.option.series[1].data = value
      }
    },
    serviceEnterRate: {
      deep: true,
      handler (value) {
        // console.log('服务人次新的值：', value)
        this.option.series[2].data = value
      }
    },
    axisDataList: {
      deep: true,
      handler (value) {
        this.option.xAxis.data = value
      }
    }
  }
}
</script>

<style lang='less'>
.left-chart-1 {
  width: 100%;
  height: 34%;
  display: flex;
  flex-grow: 0;
  flex-direction: column;

  .lc1-header {
    text-align: center;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 28px;
    margin-bottom: 10px;
  }

  .lc1-details {
    height: 50px;
    font-size: 16px;
    display: flex;
    align-items: center;
    text-indent: 20px;

    span {
      color: #096dd9;
      font-weight: bold;
      font-size: 35px;
      margin-left: 20px;
    }
  }

  .lc1-chart {
    flex: 1;
  }
}
</style>
